package spitfire.ksim.network;


/**
 * Interface for host device in the {@link KNetwork}.
 * Hosts that connect to {@link KNetwork} should implement this interface.
 * 
 * @author Adam
 *
 */
public interface KNetworkModule {
	/**
	 * Set up a connection between the network module and the given {@link KNetwork}.
	 * @param network - the network to connect to.
	 */
	public void connectNetwork(KNetwork network);
	/**
	 * Disconnect from the network.
	 */
	public void disconnectNetwork();
	/**
	 * Set network address of the network module to the given {@link KNetAddress}.
	 * @param netAddr - 
	 */
	public void setNetAddr(KNetAddress netAddr);
	/**
	 * @return the network address of the network module.
	 */
	public KNetAddress getNetAddr();
	/**
	 * @return the network that the module connected
	 */
	public KNetwork getNetwork();
	/**
	 * @param netModule - another network module.
	 * @return whether this network module is directly adjacent with the given module.
	 */
	public boolean adjacentWith(KNetworkModule netModule);
	/**
	 * Try to send a piece of data through the network to the given destination. 
	 * @param destination - the destination {@link KNetAddress}
	 * @param payload - data to be sent.
	 */
	public void send(KNetAddress destination, Object payload);
	/**
	 * Invoked when network delivers a packet to this network module.
	 * @param packet - the received packet.
	 */
	public void recv(KPacket packet);
}
